import {Component} from '@angular/core';
import {GlobalState} from '../../../global.state';
import {Router}       from '@angular/router';


@Component({
    selector: 'ba-content-top',
    styleUrls: ['./baContentTop.scss'],
    templateUrl: './baContentTop.html',
})
export class BaContentTop {

    public activePageTitle:string = '';
    private urlTitles:any;

    constructor(private _state:GlobalState, private router:Router) {
        let currentUrl = this.router.url.slice(1, this.router.url.length);

        if (currentUrl === 'dashboard') {
            currentUrl = 'DASHBOARD';
        } else if (currentUrl === 'postidea') {
            currentUrl = 'POST AN IDEA';
        } else if (currentUrl === 'listidea') {
            currentUrl = 'IDEAS';
        } else if (currentUrl === 'leaderboard') {
            currentUrl = 'LEADERBOARD';
        } else if (currentUrl === 'allTime') {
            currentUrl = 'TOP ALL-TIME';
        } else if (currentUrl === 'recent') {
            currentUrl = 'RECENT IDEAS';
        }

        this.activePageTitle = currentUrl;
        this.urlTitles = {
            '/profile': 'profile',
            '/editidea': 'edit idea'
        };

        this._state.subscribe('menu.activeLink', (activeLink) => {
            if (activeLink) {
                this.activePageTitle = activeLink.title;
            }
        });

        this._state.subscribe('menu.title', (event) => {
            if (event) {
                this.activePageTitle = this.urlTitles[event.url];
            }
        });
    }
}
